<!-- ApprovePopup.vue -->
<template>
    <el-dialog title="审批" v-model="visible" width="30%">
        <el-form :model="formData" label-width="100px">
            <el-form-item label="审批状态">
                <el-select v-model="formData.status" placeholder="请选择审批状态">
                    <el-option label="通过" value="1"></el-option>
                    <el-option label="不通过" value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="审批意见">
                <el-input v-model="formData.comment" type="textarea" :rows="4"></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="visible = false">取消</el-button>
                <el-button type="primary" @click="submitApprove">确定</el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script lang="ts" setup>
import { ref, reactive } from 'vue'
import { apiLineApprove } from '@/api/line'
import useUserStore from '@/stores/modules/user'

const userStore = useUserStore()
const visible = ref(false)
const formData = reactive({
    status: '',
    comment: '',
    user_id: userStore.userInfo.id
})

const emit = defineEmits(['success', 'close'])

const open = (id: number) => {
    formData.id = id
    visible.value = true
    formData.status = ''
    formData.comment = ''
}

const submitApprove = async () => {
    await apiLineApprove({
        id: formData.id,
        status: formData.status,
        comment: formData.comment,
        user_id: formData.user_id
    })
    emit('success')
    visible.value = false
}

defineExpose({
    open
})
</script>
